$(function () {
    // 需求1表单验证
    let form = layui.form
    form.verify({
        Pwd: [
            /^[\S]{6,12}$/,
            '请输入6到12位非空字符'
        ],
        newPwd: function (value) {
            let v1 = $('[name = oldPwd]').val()
            if (value == v1) {
                return '原密码与新密码不能一致'
            }
        },
        rePwd: function (value) {
            let v2 = $('[name = newPwd]').val()
            if (value != v2) {
                return '两次密码不一致'
            }
        }
    })
    // 需求2修改密码
    axios({
        url:'/my/updatepwd',
        method:'post',
        data: $(this).serialize(),
    }).then(res=>{
        //成功回调
        console.log(res)
        if (res.data.status) {
            return layer.msg(res.data.message)
        }
        layer.msg('恭喜你修改密码成功')
        $('#formPwd')[0].reset()
        setInterval(() => {
            window.parent.location.href='/login.html'
        }, 3000);
    });
})